package com.yyds.service.impl;

import com.yyds.mapper.PersonResidentVoMapper;
import com.yyds.mapper.VaccineVaccinatorMapper;
import com.yyds.mapper.VaccineVaccineMapper;
import com.yyds.pojo.VaccineVaccinator;
import com.yyds.service.VaccineVaccinatorService;
import com.yyds.vo.VaccineVaccinatorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("vaccineVaccinatorService")
public class VaccineVaccinatorServiceImpl implements VaccineVaccinatorService {

    @Autowired
    @Qualifier("vaccineVaccineMapper")
    private VaccineVaccineMapper vaccineVaccineMapper;

    @Autowired
    @Qualifier("vaccineVaccinatorMapper")
    private VaccineVaccinatorMapper vaccineVaccinatorMapper;

    @Autowired
    @Qualifier("personResidentVoMapper")
    private PersonResidentVoMapper personResidentVoMapper;

    @Override
    public Integer insertVaccineVaccinatorService(VaccineVaccinatorVo vo) {
        ////(vaccine_name=B型新冠疫苗, resident_name=打的)
        VaccineVaccinator vaccineVaccinator = new VaccineVaccinator();
        Integer vaccine_id = vaccineVaccineMapper.queryVaccineIdMapper(vo.getVaccine_name());
        vaccineVaccinator.setVaccine_id(vaccine_id);
        System.out.println("vaccineVaccinator vaccineVaccineMapper = " + vaccineVaccinator);
        Integer resident_id = personResidentVoMapper.queryVaccineIdMapper(vo.getResident_name());
        vaccineVaccinator.setResident_id(resident_id);
        System.out.println("vaccineVaccinator personResidentVoMapper = " + vaccineVaccinator);
        return vaccineVaccinatorMapper.insertVaccineVaccinatorMapper(vaccineVaccinator);
    }

    @Override
    public Integer deleteVaccineVaccinatorService(Integer vaccinator_id) {
        return vaccineVaccinatorMapper.deleteVaccineVaccinatorMapper(vaccinator_id);
    }

    @Override
    public Integer deleteAllVaccineVaccinatorService(String str) {
        //1-2-3-4-
        List<Integer> list = new ArrayList<>();
        String[] strs = str.split("-");
        for (int i = 0; i < strs.length; i++) {
            list.add(Integer.parseInt(strs[i]));
        }
        return vaccineVaccinatorMapper.deleteAllVaccineVaccinatorMapper(list);
    }

    @Override
    public Integer updateVaccineVaccinatorService(VaccineVaccinatorVo vo) {
        Integer vaccine_id = vaccineVaccineMapper.queryVaccineIdMapper(vo.getVaccine_name());
        Integer resident_id = personResidentVoMapper.queryVaccineIdMapper(vo.getResident_name());
        Integer vaccinator_id = vo.getVaccinator_id();
        VaccineVaccinator newVaccinator = new VaccineVaccinator(vaccinator_id, resident_id, vaccine_id);
        VaccineVaccinator oldVaccinator = vaccineVaccinatorMapper.querySingleVaccineVaccinatorMapper(newVaccinator.getVaccinator_id());
        return vaccineVaccinatorMapper.updateVaccineVaccinatorMapper(oldVaccinator, newVaccinator);
    }

}
